package cn.e4j.modular.system.service.impl;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.system.entity.SysRoleModule;
import cn.e4j.modular.system.mapper.SysRoleModuleMapper;
import cn.e4j.modular.system.service.SysRoleModuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 功能模块-角色关联表 服务实现类
 * </p>
 *
 * @author wenchuan.li
 * @since 2018-12-06
 */
@Service
public class SysRoleModuleServiceImpl extends ServiceImpl<SysRoleModuleMapper, SysRoleModule> implements SysRoleModuleService {

    @Transactional(readOnly = true)
    @Override
    public List<Map<String, String>> selectMenusOfRoles(List<Map<String, String>> roles, Dto dto){
        return this.baseMapper.selectMenusOfRoles(roles, dto);
    }

    @Transactional(readOnly = true)
    @Override
    public List<String> getRoleModulesList(String id){
        return this.baseMapper.getRoleModulesList(id);
    }

    @Transactional
    @Override
    public void saveRoleModulesList(List<SysRoleModule> lists) {
        if(lists.size() > 0){
            this.baseMapper.delteRoleModulesByRoleId(lists.get(0).getROLE_ID());
        }
        for (SysRoleModule sysRoleModule : lists) {
            this.baseMapper.insert(sysRoleModule);
        }
    }
}
